<template>
  <div class="images-show">
    <el-carousel class="big-img"
                 ref="imageList"
                 height="500px"
                 direction="vertical"
                 :autoplay="false"
                 indicator-position="none">
      <el-carousel-item v-for="item in imagesShowDate" :key="item.id" name="item.id">
        <img :src="item.url" align="middle">
      </el-carousel-item>
    </el-carousel>

    <div class="images-list">
      <div class="images-list-item arrow" @click="toPrev">
        <!--   上一页-->
        <img src="../../assets/icons/left.png" />
      </div>
      <div v-for="item in imagesShowDate"
           :class="item.id === defaultImageId ? 'images-list-item  active-item' : 'images-list-item '"
           :key="item.id"
           @click="clickTo(item.id)">
        <img
          :src="item.url">
      </div>

      <div class="images-list-item arrow"  @click="toNext">
        <!-- 下一页-->
        <img src="../../assets/icons/right.png"/>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  // 图片展示，点击图片列表，切换图片
  name: 'imagesShow',
  data () {
    return {
      defaultImageId: 1
    }
  },
  props: [ 'imagesShowDate' ],
  watch: {
    imagesShowDate (val) {
      this.defaultImageId = val[0].id
    }
  },
  methods: {
    toPrev () {
      if (this.defaultImageId > 1) {
        this.$refs.imageList.prev()
        this.defaultImageId -= 1
      }
    },
    toNext () {
      if (this.defaultImageId < this.imagesShowDate.length) {
        this.$refs.imageList.next()
        this.defaultImageId += 1
      }
    },
    clickTo (index) {
      this.$refs.imageList.setActiveItem(index - 1)
      this.defaultImageId = index
    }

  }
}
</script>

<style lang="scss">
  $width: 100%;
.images-show {
  width: $width;
  .big-img {
    img {
      height: 100%;
      margin: 0 auto;
      display: block;
    }
  }
  .images-list {
    margin: 0 auto;
    .images-list-item {
      width: 100px;
      height: 100px;
      cursor: pointer;
      display: flex;
      align-items: center;
      background-color: #e4e7ed;
      display: inline-grid;
      margin-left: 8px;
      img {
        height: 100%;
      }

      &:hover {
        background-color: #f3923d;
      }
    }
    .active-item {
      background-color: #f3923d;
    }
    .arrow {
      background-color: #ffffff;
      img {
        width: 50%;
        margin: 0 auto;
      }

    }
  }
}
</style>
